﻿@model IEnumerable<MedalToUser>
@{
    ViewData["Title"] = new string[] { "勋章馆" };
}
<div class="container">
    <h5 class="tn-first-title">勋章馆</h5>
    <div class="row">
        <div class="col-xs-9" id="_ListMedalShop">
            @Html.Action("_ListMedalShop", "UserSpace")
        </div>
        <div class="col-xs-3">
            @if (Model.Any())
            {
                <div class="tn-gray-bg tn-mb-20">
                    <div class="tn-title">
                        <h5>勋章获取记录</h5>
                    </div>
                    <div class="jh-medal-record">
                        @foreach (var medaltoUser in Model)
                        {
                            <a href="@SiteUrls.Instance().SpaceHome(medaltoUser.UserId)" class="media">
                                <div class="media-left">
                                    @Html.ShowUserAvatar(userId: medaltoUser.UserId, avatarSizeType: AvatarSizeType.Small, enableNavigate: false, isShowUserCard: false)
                                </div>
                                <div class="media-body">
                                    <h5 class="media-heading" title="@medaltoUser.UserDisplayName">@StringUtility.Trim(medaltoUser.UserDisplayName, 5)<small class="pull-right tn-mt-5">@medaltoUser.DateCreated.ToFriendlyDate()</small></h5>
                                    <p class="text-muted">获得 @medaltoUser.GetMedalInfo().MedalName 勋章</p>
                                </div>
                            </a>
                        }
                    </div>
                </div>
            }

        </div>
    </div>
</div>
<script type="text/javascript">
    require(['jquery', 'tnlayer'], function ($, tnlayer) {
        $(document).on("click", ".medaltouserdeal", function () {
            //点击申请，取消申请，放弃勋章操作
            var $this = $(this);
            var medaltoUserId = $this.data("medaltouserid");
            var method = $this.data("method");
            if (method == "Abandoned") {
                layer.confirm("确定放弃么？", {
                    btn: ['确认', '取消'],//按钮
                    scrollbar: false
                }, function () {
                    var url = '@CachedUrlHelper.Action("ChangeMedaltoUserStatus", "UserSpace")';
                    $.post(url, { medaltoUserId: medaltoUserId, method: method }, function (data) {
                        if (data.MessageType == 1) {
                            GetMedalShopList();
                            layer.msg(data.MessageContent, { icon: 1 });
                        }
                        else {
                            layer.msg(data.MessageContent, { icon: 2 });
                        }
                    });
                });
            }
            else {
                var url = '@CachedUrlHelper.Action("ChangeMedaltoUserStatus", "UserSpace")';
                $.post(url, { medaltoUserId: medaltoUserId, method: method }, function (data) {
                    if (data.MessageType == 1) {
                        GetMedalShopList();
                        layer.msg(data.MessageContent, { icon: 1 });
                    }
                    else {
                        layer.alert(data.MessageContent, { icon: 2 });
                    }
                });
            }

        });

        //刷新勋章馆勋章列表
        function GetMedalShopList() {
            var url = '@CachedUrlHelper.Action("_ListMedalShop", "UserSpace")?t=' + (new Date).getTime();
            $.get(url, function (data) {
                $("#_ListMedalShop").html(data);
            })
        }
    })
</script>